package　com
{
	import flash.display.ActionScriptVersion;
	import flash.display.Bitmap;
	import flash.display.Sprite;
	import flash.display.BitmapData;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	
	
	/**
	 * ...
	 * @author anzhilin
	 */
	public class Avatar extends Sprite 
	{
		/**
		 * 序列图
		 */
		private var bmd:BitmapData;
		/**
		 * 角色移动方向
		 */
		public var direct:int;
		/**
		 * 序列图数组
		 */
		private var avatarArr:Array;
		/**
		 * 帧频
		 */
		private var frame:int;
		/**
		 * 位图序列索引
		 */
		private var index:int;
		/**
		 * 角色宽
		 */
		private static const AVATAR_W:int=61;
		/**
		 * 角色高
		 */
		private static const AVATAR_H:int = 105;
		/**
		 * 角色
		 */
		private var avatar:Bitmap;
		/**
		 * 当前位置
		 */
		public var currentLoc:Point;
		/**
		 * 目标位置
		 */
		public var targetLoc:Point;
		
		public function Avatar(source:BitmapData) 
		{
			bmd = source;
			avatarArr = new Array();
			init();
			avatar = new Bitmap(avatarArr[0][0]);
			addChild(avatar);
		}
		private function init():void
		{
			avatarArr = this.divide();
			//trace(avatarArr.length);
		}
		/**
		 * 将序列图拆分成位图数组
		 * @return 位图数组
		 */
		private function divide():Array
		{
			var bmdArr:Array=new Array();
			var sourceRow:int = int(bmd.height / AVATAR_H);	//序列图的行数
			var sourceCol:int = int(bmd.width / AVATAR_W);	//序列图的列数
			
			for (var i:int = 0; i < sourceRow; i++ )
			{
				var tempArr:Array = new Array();
				for (var j:int = 0; j < sourceCol; j++ )
				{
					var tempBmd:BitmapData = new BitmapData(AVATAR_W, AVATAR_H);
					tempBmd.copyPixels(bmd, new Rectangle(j * AVATAR_W, i * AVATAR_H, AVATAR_W, AVATAR_H), new Point(0, 0));
					tempArr.push(tempBmd);
				}
				bmdArr.push(tempArr);
			}
			return bmdArr;
		}
		public function moveTo(curLoc:Point, tarLoc:Point):void
		{
			this.x += 4;
			this.y += 4;
		}
		
	}

}